package com.example.controller;

import com.example.api.Result;
import com.example.configura.LogOperation;
import com.example.params.EmpQueryParam;
import com.example.pojo.Emp;
import com.example.service.EmpService;
import com.example.vo.empvo.EmpListVo;
import com.example.vo.empvo.GetAllEmpInfoVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.List;
@Slf4j
@RestController
@RequestMapping("/emps")
public class EmpController {
    @Autowired
    private EmpService empService;
    @GetMapping
    public Result<GetAllEmpInfoVo> getAllEmpInfo(EmpQueryParam queryParam) {
        log.info("查询所有员工信息,展示到员工管理页面");
        return Result.success(empService.getAllEmpInfo(queryParam));
    }
    @GetMapping("/list")
    public Result<List<EmpListVo>> getAllEmpList() {
        log.info("查询所有员工信息,展示到班级新增页面");
        return Result.success(empService.getAllEmpList());
    }
    @DeleteMapping
    @LogOperation
    public Result<String> deleteEmpByIds(@RequestParam List<Integer> ids) {
        log.info("批量删除员工信息,ids:{}", ids);
        empService.deleteEmpByIds(ids);
        return Result.success(null);
    }
    @GetMapping("/{id}")
    public Result<Emp> getEmpInfoById(@PathVariable Integer id) {
        log.info("查询员工信息,id:{}", id);
        return Result.success(empService.getEmpInfoById(id));
    }
    @PutMapping
    @LogOperation
    public Result<String> updateEmp(@RequestBody Emp emp) {
        log.info("修改员工信息,emp:{}", emp);
        empService.updateById(emp);
        return Result.success(null);
    }
    @PostMapping
    @LogOperation
    public Result<String> addEmp(@RequestBody Emp emp) {
        log.info("添加员工信息,emp:{}", emp);
        empService.addEmp(emp);
        return Result.success(null);
    }
}
